home *** CD-ROM | disk | FTP | other *** search
- /* These functions for getting the "Poor Man's Search Path" were
- adapted from TechNote #238. These functions won't (or
- aren't supposed to) work under AUX 1.1, but I don't wan't
- to worry about buggy Apple software which has probably
- been fixed for AUX 2.0 (though the delimiter is always
- ':' while in AUX it's a '/').
-
- I have not tested these functions since I don't need them. */
-
- #include <limits.h>
- #include <string.h>
- #include "MemoryLib.h"
- #include "StringLib.h"
- #include "FileLib.h"
-
- /* Given a directory ID and volume reference number this constructs
- a pathname specifying the directory. */
- OSErr FilePathFromDir(FileDirType dir, FileVolType vol, FilePathType path)
- {
- BEGIN
- CInfoPBRec pb;
- FilePathType dirname;
- FilePathType fname;
- short length;
- OSErr err = noErr;
-
- /* save file name and its length */
- strcpy(path, fname);
- if (*fname == ':')
- memmove(fname, fname+1, strlen(fname));
- length = strlen(fname);
- *path = 0;
-
- /* initialize parameter block */
- *dirname = 0;
- memset(&pb, 0, sizeof(pb));
- pb.dirInfo.ioNamePtr = (StringPtr) dirname;
- pb.dirInfo.ioDrParID = dir;
-
- /* append the names of each parent directory until we reach the root */
- do {
- pb.dirInfo.ioVRefNum = vol;
- pb.dirInfo.ioFDirIndex = -1;
- pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID;
- err = PBGetCatInfo(&pb, false);
-
- /* append name of directory after making sure there's room in string */
- if (! err) {
- PtoCstr(dirname);
- if (length + strlen(dirname) + 1 < sizeof(FilePathType)-1) {
- strcat(dirname, ":");
- strcpy(path, dirname);
- CtoPstr(dirname);
- }
- else
- err = bdNamErr;
- }
-
- } while (! err && pb.dirInfo.ioDrDirID != fsRtDirID);
-
- /* append original file name */
- if (! err)
- strcat(path, fname);
-
- return(err);
- END
- }
-
- /* Given a working directory and a partial path name this builds the full
- path name. The working directory could be a volume reference number
- such as that returned by SFGetFile. */
- OSErr FilePathFromWD(FileWDirType wd, FilePathType path)
- {
- BEGIN
- FileDirType dir;
- FileVolType vol;
- long procid;
- OSErr err = noErr;
-
- err = GetWDInfo(wd, &vol, &dir, &procid);
- if (! err)
- err = FilePathFromDir(dir, vol, path);
- return(err);
- END
- }
-